﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqlCustomCompiler.Model;
using Xtensive.Orm;
using Xtensive.Orm.Configuration;

namespace SqlCustomCompiler
{
  public class Program
  {
    public static void Main(string[] args)
    {
      // Loading domain configuration section with name "Default".
      var domainConfiguration = DomainConfiguration.Load("Default");
      var domain = Domain.Build(domainConfiguration);

      using (var session = domain.OpenSession())
      using (var tx = session.OpenTransaction()) {
        // Create some messages
        new Message(session, "Hello");
        new Message(session, "Goodbye");
        new Message(session, "Welcome");
        new Message(session, "Adios");
        new Message(session, "IDDQD");
        new Message(session, "IDFKA");

        Console.WriteLine("Messages ending with 'e':");
        var query1 = session.Query.All<Message>().Where(m => m.Text.Like("%e"));
        foreach (var m in query1)
          Console.WriteLine(m.Text);

        Console.WriteLine("Messages starting with 'ID':");
        var query2 = session.Query.All<Message>().Where(m => m.Text.Like("ID%"));
        foreach (var m in query2)
          Console.WriteLine(m.Text);

        Console.WriteLine("Messages containing 'o':");
        var query3 = session.Query.All<Message>().Where(m => m.Text.Like("%o%"));
        foreach (var m in query3)
          Console.WriteLine(m.Text);
      }
    }
  }
}
